package com.lmqb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmqb.bean.JCollection;
import com.lmqb.bean.LmCreditPromote;
import com.lmqb.bean.LmLoan;
import com.lmqb.bean.LmRepay;
import com.lmqb.bean.LmUser;
import com.lmqb.bean.LmUserInfo;
import com.lmqb.dao.JCollectionMapper;
import com.lmqb.dao.LmLoanMapper;
import com.lmqb.dao.LmRepayMapper;
import com.lmqb.dao.LmUserInfoMapper;
import com.lmqb.dao.LmUserMapper;
import com.lmqb.page.PageTool;
import com.lmqb.page.RepayPager;
import com.lmqb.service.RepayService;
import com.lmqb.util.StrUtil;

@Service("repayService")
public class RepayServiceImpl implements RepayService{

	@Autowired
	private LmRepayMapper repayDao;
	
	@Autowired
	private LmUserMapper lmUserDao;
	
	@Autowired
	private LmUserInfoMapper lmUserInfoDao;
	
	@Autowired
	private LmLoanMapper lmLoanDao;
	
	@Autowired
    private	JCollectionMapper JCollectionDao;
	//逾期用户
	public RepayPager selectRepayPager(RepayPager pagerModel) {
		List<LmRepay> list=repayDao.selectAll(pagerModel);
		List<LmUserInfo> userInfoList=lmUserInfoDao.selectAll();
		for(int i=0;i<list.size();i++){
			list.get(i).setRepayEndTimeD(StrUtil.intToTime(list.get(i).getRepayEndTime()));
			for(int j=0;j<userInfoList.size();j++){
				if(list.get(i).getUserId()==userInfoList.get(j).getUserId()){
					list.get(i).setUserName(userInfoList.get(j).getUserName());
					break;
				}
			}
		}
		pagerModel.setList(list);
		int count = repayDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}

	
	public LmLoan selectByPrimaryKey(String loanNo) {
		LmLoan lmLoan = lmLoanDao.selectByPrimaryKey(loanNo);
		return lmLoan;
	}


	@Override
	public int insert(JCollection record) {
		int insert = JCollectionDao.insert(record);
		return insert;
	}


	//还款信息根据还款订单
	public LmRepay selectByPrimaryKey1(String repayNo) {
		LmRepay lmRepay = repayDao.selectByPrimaryKey(repayNo);
		return lmRepay;
	}

	
	 
}
